package com.huoyun.common.action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.huoyun.base.action.BaseAction;
import com.huoyun.cargo.service.CargoService;
import com.huoyun.common.bean.BidInfo;
import com.huoyun.common.bean.BidInfoItem;
import com.huoyun.common.model.InviteCarModel;
import com.huoyun.common.service.BidInfoService;
import com.huoyun.common.service.InviteCarService;

public class BidGoodsAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 管理应标信息的service
	 */
	private BidInfoService bidInfoService;
	/**
	 * 管理货物的service
	 */
	private CargoService cargoService;
	/**
	 * 车主主动应标的详细应标信息列表
	 */
	private List<BidInfoItem> myBiddingInfoList;
	/**
	 * 车主已经达成的应标详细信息列表
	 */
	private List<BidInfoItem> mySuccessBidInfoList;
	/**
	 * 车主收到的邀请的详细信息列表
	 */
	private List<InviteCarModel> myInviteCarModelList;
	/**
	 * 管理车辆邀请的service
	 */
	private InviteCarService inviteCarService;
	
	/**
	 * 一条应标信息
	 */
	private BidInfo bidInfo;
	
	public BidInfoService getBidInfoService() {
		return bidInfoService;
	}

	public void setBidInfoService(BidInfoService bidInfoService) {
		this.bidInfoService = bidInfoService;
	}	

	public CargoService getCargoService() {
		return cargoService;
	}

	public void setCargoService(CargoService cargoService) {
		this.cargoService = cargoService;
	}

	public List<BidInfoItem> getMyBiddingInfoList() {
		return myBiddingInfoList;
	}

	public void setMyBiddingInfoList(List<BidInfoItem> myBiddingInfoList) {
		this.myBiddingInfoList = myBiddingInfoList;
	}

	public List<BidInfoItem> getMySuccessBidInfoList() {
		return mySuccessBidInfoList;
	}

	public void setMySuccessBidInfoList(List<BidInfoItem> mySuccessBidInfoList) {
		this.mySuccessBidInfoList = mySuccessBidInfoList;
	}

	public List<InviteCarModel> getMyInviteCarModelList() {
		return myInviteCarModelList;
	}

	public void setMyInviteCarModelList(List<InviteCarModel> myInviteCarModelList) {
		this.myInviteCarModelList = myInviteCarModelList;
	}

	public InviteCarService getInviteCarService() {
		return inviteCarService;
	}

	public void setInviteCarService(InviteCarService inviteCarService) {
		this.inviteCarService = inviteCarService;
	}

	public BidInfo getBidInfo() {
		return bidInfo;
	}

	public void setBidInfo(BidInfo bidInfo) {
		this.bidInfo = bidInfo;
	}

	/**
	 * myBiddingInfoList: 车主主动应标，等待货主确认的列表
	 * myBiddedInfoList:  货主邀请应标，等待车主确认的列表
	 * mySuccessBidInfoList: 双方已经达成的交易
	 * @return SUCCESS
	 */
	public String showMyBiddedGoods() {
		
		long userId = getLoginUser().getId();
		
		this.myBiddingInfoList = bidInfoService.getBidInfoItemByStatusForUser(userId, 0);
		
		this.myInviteCarModelList = inviteCarService.getInviteCarModelListByUserId(userId);
		
		this.mySuccessBidInfoList = bidInfoService.getBidInfoItemByStatusForUser(userId, 2);
		
		return SUCCESS;
	}
	
	/**
	 * 删除一条应标信息
	 * @return
	 */
	public String deleteBidInfoById() {
		
		int bidInfoId = Integer.parseInt(getRequest().getParameter("bidInfoId"));
		bidInfoService.deleteBidInfoById(bidInfoId);
		
		return SUCCESS;
	}
	
	/**
	 * 车辆接受一个货物应标
	 * @return 
	 */
	public String acceptInvitedBidById() {
		
		long inviteId = Long.parseLong(getRequest().getParameter("inviteCarId"));
		long goodsId = Long.parseLong(getRequest().getParameter("goodsId"));
		long carId = Long.parseLong(getRequest().getParameter("carId"));
		String price = getRequest().getParameter("price");
		bidInfo = new BidInfo();
		bidInfo.setCarId(carId);
		bidInfo.setGoodsId(goodsId);
		bidInfo.setPrice(price);
		bidInfo.setInviteId(inviteId);
		
		bidInfoService.saveBidInfo(bidInfo);
		inviteCarService.delete(inviteId);
		
		return SUCCESS;
	}
}